#ifndef FILESMANAGER_H
#define	FILESMANAGER_H

#include <vector>
#include <fstream>
#include <iostream>
#include <sstream>
#include "Singleton.h"
#include "Global.h"


int scale(double xsc, double ysc);
int setpen(int ipen);
int drawto(double xsc, double ysc);
int moveto(double xsc, double ysc);

class FilesManager : public Singleton<FilesManager> {
public:
    FilesManager();
   // FilesManager(const FilesManager& orig);
    virtual ~FilesManager();

    void SetDir(const std::string& xdir);
    int SaveOUT(int iwkod, int iw, int ie, int ichl, int mw, int nw,
            std::vector<int>& v_ndt, std::vector<double>& v_tchcal,
            std::vector<std::vector<double> >& v_t, std::vector<bool>& v_show_t);

    int SaveDATs(const std::string& typ, int ichl, int iw, std::vector<std::vector<double> >& v_t);
    int SaveTEMLOGs(int ichl, const std::vector<int>& v_idt, const std::vector<std::vector<std::vector<double> > >& v_tpc);
    int SaveMSH000(const std::string& typ, double *x, int nlv, int nlh);
    int LoadMSH();
    int SaveMSH();
    int SaveBLNs(const std::string& typ);
    int SavePLG(const std::string& typ, const std::vector<std::vector<double> >& vv_plg);
    int SaveTLG(const std::string& typ, int xistem, const std::vector<std::vector<double> >& vv_tlg);
    void LoadINP(const std::string& typ);
    template <typename T> T FromString(std::string& s);

    bool isMeshingNeeded();


    int sett(const std::string& finame, double sc, int n,
            double *xz, double *yz, double *rz, double *xrz,
            double *yrz, double *alp, double *alk, double *t);

    std::ofstream FL17;
    std::ofstream FL2;
    std::ofstream FL7;

private:
    int skipinp(std::string &dana);
    int piszbrg(int mw, int nw, double *xw, double rnorm);
    int piszbln(int mw, int nw, double *xw, double rnorm);

    int podz(int me, int ne, int nw);
    int wycin(int ie, int ne, int kkod1, int kkod2, int kkod3, int kkod4);

    std::ifstream FL1;

    std::ofstream FL4;
    std::ofstream FL19;
    std::ofstream FL18;

};

template <typename T> T FilesManager::FromString(std::string& s) {
    skipinp(s);

    std::istringstream myStream(s);
    T num;
    myStream >> num;
    if (!myStream) {
        std::cout << "Blad, argument nie jest liczba" << std::endl;
        return 0;
    } else
        return num;
}


#define FM FilesManager::GetSingleton()
//#define FM FilesManager::*FilesManager

#endif	
